﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FimetContoDeposito.DAL
{
    public interface IFacadeBase
    {
        void Initialize();
        void Dispose();
    }

    //public abstract class FacadeBase : IDisposable
    //{
    //    public FacadeBase()
    //    {

    //    }

    //    public abstract void Initialize();

    //    public abstract void Dispose();
    //}

    /*
public class BaseClass : IDisposable
{
    private bool _disposed = false;
    ~BaseClass()
    {
        Dispose(false);
    }

    public void Dispose()
    {
        Dispose(true);
        GC.SuppressFinalize(true);
    }

    protected virtual void Dispose(bool disposing)
    {
        if (_disposed)
            return;

        if (disposing)
        {
            //release managed resources
        }

        //release unmanaged resources

        _disposed = true;
    }
}

public void Derived : BaseClass
{
    private bool _disposed = false;

    protected override void Dispose(bool disposing)
    {
        if (_disposed) 
            return;

        if (disposing)
        {
            //release managed resources
        }

        //release unmanaged resources

        base.Dispose(disposing);
        _disposed = true;
    }     
     */
    public abstract class FacadeBase<T> : IFacadeBase, IDisposable where T : class, new()
    {
        public FacadeBase()
        {

        }

        public static T Create()
        {
            T retValue = new T();

            ((IFacadeBase)retValue).Initialize();

            return retValue;
        }

        public abstract void Initialize();

        public abstract void Dispose();

        public Repository<E, Ekey> GetRepository<E, Ekey>(DbContext context) 
            where E : class
            //where Context : DbContext, new()
        {
            return new Repository<E, Ekey>(context);
        }
    }
}
